import { IPSModelSortable } from '../../ipsmodel-sortable';
import { IPSAppDELogic } from '../../app/dataentity/ipsapp-delogic';
import { IPSDELogic } from './ipsdelogic';
import { IPSDELogicNode } from './ipsdelogic-node';
import { IPSDELogicParam } from './ipsdelogic-param';
import { IPSSysSFPlugin } from '../../res/ipssys-sfplugin';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDELogicImpl extends PSModelObjectImpl implements IPSDELogic, IPSAppDELogic, IPSModelSortable {
  get codeName(): string {
    return this.M.codeName;
  }

  get debugMode(): 0 | 1 {
    return this.M.debugMode != null ? this.M.debugMode : 0;
  }

  get defaultParamName(): string {
    return this.M.defaultParamName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get logicName(): string {
    return this.M.logicName;
  }

  get logicSubType(): 'NONE' | 'DEFIELD' | 'USER' | 'USER2' | 'USER3' | 'USER4' {
    return this.M.logicSubType || 'NONE';
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected psdelogicnodes: IPSDELogicNode[] | null = null;

  getPSDELogicNodes(): IPSDELogicNode[] | null {
    if (this.psdelogicnodes == null) {
      this.psdelogicnodes = this.fillChildListModel(this.M.getPSDELogicNodes, 'dataentity.logic.IPSDELogicNode') as IPSDELogicNode[];
    }
    return this.psdelogicnodes;
  }

  get psDELogicNodes(): IPSDELogicNode[] | null {
    return this.getPSDELogicNodes();
  }

  findPSDELogicNode(objKey: any): IPSDELogicNode | null {
    return this.getPSModel5('dataentity.logic.IPSDELogicNode', this.getPSDELogicNodes(), objKey) as IPSDELogicNode;
  }

  protected psdelogicparams: IPSDELogicParam[] | null = null;

  getPSDELogicParams(): IPSDELogicParam[] | null {
    if (this.psdelogicparams == null) {
      this.psdelogicparams = this.fillChildListModel(this.M.getPSDELogicParams, 'dataentity.logic.IPSDELogicParam') as IPSDELogicParam[];
    }
    return this.psdelogicparams;
  }

  get psDELogicParams(): IPSDELogicParam[] | null {
    return this.getPSDELogicParams();
  }

  findPSDELogicParam(objKey: any): IPSDELogicParam | null {
    return this.getPSModel5('dataentity.logic.IPSDELogicParam', this.getPSDELogicParams(), objKey) as IPSDELogicParam;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后台扩展插件');
    }
    return value;
  }

  get scriptCode(): string {
    return this.M.scriptCode;
  }

  protected startpsdelogicnode: IPSDELogicNode | null = null;

  getStartPSDELogicNode(): IPSDELogicNode | null {
    if (this.startpsdelogicnode != null) return this.startpsdelogicnode;
    const value = this.M.getStartPSDELogicNode;
    if (value == null) {
      return null;
    }
    this.startpsdelogicnode = this.findPSDELogicNode(value);
    return this.startpsdelogicnode;
  }

  get startPSDELogicNode(): IPSDELogicNode | null {
    return this.getStartPSDELogicNode();
  }

  getStartPSDELogicNodeMust(): IPSDELogicNode {
    const value = this.getStartPSDELogicNode();
    if (value == null) {
      throw new Error('未指定开始处理节点');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get customCode(): boolean {
    return this.M.customCode != null ? this.M.customCode : false;
  }

  get enableBackend(): boolean {
    return this.M.enableBackend;
  }

  get enableFront(): boolean {
    return this.M.enableFront;
  }

  get cls(): string {
    return 'PSDELogicImpl';
  }

  instanceof(cls: string): boolean {
    if (
      cls == 'IPSModelSortable' ||
      cls == 'app.IPSApplicationObject' ||
      cls == 'app.dataentity.IPSAppDELogic' ||
      cls == 'app.dataentity.IPSAppDataEntityObject' ||
      cls == 'dataentity.logic.IPSDELogic'
    )
      return true;
    return super.instanceof(cls);
  }
}
